import { Message } from 'element-ui';
import { exchangeShopitem } from '@/api/mall/';
import { userInfo } from '@/api/login';
import { set } from '@/common/utils';

export default {
  state: {},
  mutations: {},
  actions: {
    async exchange({ rootState, commit }, { id }) {
      await exchangeShopitem({ id });

      // eslint-disable-next-line
      const user = await userInfo({ id: rootState.user.user._id });

      commit('saveUser', { user });

      set('user', user);

      Message({
        message: '兑换成功啦!',
        type: 'success',
      });
    },
  },
};
